﻿<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.Map,java.util.HashMap" %>
<%@ page import="weaver.hrm.*" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.general.BaseBean" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="bb" class="weaver.general.BaseBean" scope="page" />
<%!
/**
 * 
 * @Title: getFormFieldMap
 * @Description: TODO(根据表单id和明细表序号[从1开始计算明细表]获取字段列表)
 * @param @param formid
 * @param @param num
 * @param @return 设定文件
 * @return Map<String,String> 返回类型
 * @throws
 */
public Map<String, String> getFormFieldMap(int formid, String num) {
	Map<String, String> array = new HashMap<String, String>();
	RecordSet rs = new RecordSet();
	formid = Math.abs(formid);
	String sql = "";
	sql = "select tablename from workflow_bill where id=-"+formid;
	rs.execute(sql);
	if(rs.next()){
		String tablename = Util.null2String(rs.getString("tablename")).toLowerCase();
		if ("0".equals(num)) {
			sql = "select b.id,b.fieldname,b.detailtable from workflow_billfield b where b.billid=-"+ formid+ " and (b.detailtable = '' or b.detailtable is null) ";
		} else {
			sql = "select b.id,b.fieldname,b.detailtable from workflow_billfield b where b.billid=-"+ formid+ " and b.detailtable='"+tablename+"_dt" + num + "'";
		}
		rs.execute(sql);
		while (rs.next()) {
			array.put(Util.null2String(rs.getString("fieldname")).toLowerCase(),Util.null2String(rs.getString("id")));
		}
	}
	return array;
}
%>

<%
User user = HrmUserVarify.getUser (request , response) ;
if(user == null)  return ;
/**
String isIE = (String)session.getAttribute("browser_isie");
if (isIE == null || "".equals(isIE)) {
	isIE = "true";
	session.setAttribute("browser_isie", "true");
}
**/
int type = Util.getIntValue(request.getParameter("type"));//0：查看；1：创建；2：编辑；3：监控
int formmodeid = Util.getIntValue(request.getParameter("formmodeid"));//模块id
String billid = Util.null2String(request.getParameter("billid"));//数据id
int formid = Util.getIntValue(request.getParameter("formid"));//表单id
String url = Util.null2String(request.getParameter("url"));//请求url串

int resourceId = user.getUID();//当前用户的id
//查询当前用户所在的分部
RecordSet rs1 = new RecordSet();
int value = -1;
String sql1 = "";
sql1 = "select * from hrmresource where id="+resourceId;
rs1.execute(sql1);
if(rs1.next()){
	value  = Util.getIntValue(rs1.getString("subcompanyid1"));
}


Calendar today = Calendar.getInstance();
String currentdate = Util.add0(today.get(Calendar.YEAR), 4) + "-" +
                     Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-" +
                     Util.add0(today.get(Calendar.DAY_OF_MONTH), 2) ;//当前日期 格式为 1992-01-01
String currenttime = Util.add0(today.get(Calendar.HOUR_OF_DAY), 2) + ":" +
                     Util.add0(today.get(Calendar.MINUTE), 2) + ":" +
                     Util.add0(today.get(Calendar.SECOND), 2) ;//当前时间 格式为11:30:30
%>
<%-- 获取表单字段map的代码段 2016-4-19 12:15:56 start --%>
<%

Map<String, String> arrayM = new HashMap<String, String>();
arrayM = getFormFieldMap(formid, "0");//主表字段map<name,id>

%>
<%-- 获取表单字段map的代码段 2016-4-19 12:15:56 start --%>
<%
/**此处可以编写自己的自定义java代码***/
	//获取上周周一 周日的日期
	Calendar cal = Calendar.getInstance(); 
	int n = cal.get(Calendar.DAY_OF_WEEK) - 1; 
	if (n == 0) { 
	    n = 7; 
	} 
	cal.add(Calendar.DATE, -(7 + (n - 1)));// 上周一的日期 
	Date monday = cal.getTime(); 
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	String monDay = sdf.format(monday);
	cal.add(Calendar.DATE, 6); 
	Date sunday = cal.getTime(); 
	String sunDay = sdf.format(sunday);
	//-----------获取当前日期为星期几
	int weekDay = today.get(Calendar.DAY_OF_WEEK)-1;

%>
<script type="text/javascript"  src ="/js/workflow/VCEventHandle_wev8.js" ></script>
<script type="text/javascript">
//----表单建模标准字段获取-----
var stype = "<%=type%>";//0：查看；1：创建；2：编辑；3：监控

if(stype=="0"||stype=="3"){//查看||监控
}
if(stype=="1"||stype=="2"){//创建||编辑
}

//-----字段id获取-----
var nf_mafi = "<%=arrayM.get("nf")%>";//年份-M
var zb_mafi = "<%=arrayM.get("zb")%>";//年份-M
//-------------------------------------------
var weekDay = <%=weekDay%>;
var monDay = "<%=monDay%>";
var sunDay = "<%=sunDay%>";
//-----周别起始日期----
var zqsrq_mafi = "<%=arrayM.get("zqsrq")%>";
//-----周别结束日期----
var zjsrq_mafi = "<%=arrayM.get("zjsrq")%>";
//------------------------------------------
var  value1 = <%=value%>;
//var number = 1;
jQuery(document).ready(function(){
	//取得button按钮的节点  用来记录点击次数
	/* var addbutton0 = document.getElementById("$addbutton0$");
	jQuery(addbutton0).click(function(){
		number = number + 1;
	}); */
	if(stype=="1"||stype=="2"){		
		checkCustomize = function (){
			if(value1 == 5 || value1 == 0){
				return true;	
			}else{
				var flag01 = Checkbox01();
				var flag02 = Checkbox02();
				//return flag02;
				return flag01 && flag02;
			}
			
	    }
	}
});

//---填报周别只能为当前日期的上一周的
function Checkbox01(){
	var nf_mafv = jQuery("#field"+nf_mafi).val();//年份---实际值
    var zb_mafe = jQuery("#field"+zb_mafi+"span").val();//周别---显示值
    //------------获取周别日期
    var zqsrq = jQuery("#field"+zqsrq_mafi).val();
    var zjsrq = jQuery("#field"+zjsrq_mafi).val();
    
    if(zqsrq == monDay && zjsrq == sunDay){
    	if(weekDay == 1 || weekDay == 2 || weekDay == 3){
    		return true;
    	}else{
    		alert("上报时间为周一至周三");
    		return false;
    	}
    }else{
    	alert("请录入上周周报");
    	return false;
    } 
}
// 用来验证类别是否重复
function Checkbox02(){

	var subrow = jQuery("input[name=check_mode_0]");//check_mode_0 中的0表示第一个子表，子表没一行都有一个隐藏元素，记录当前行号
	var array = new Array();
	for(var i=0; i<subrow.length; i++){
		var row = subrow.get(i).value;//每一行的行号
		//var val =  jQuery("#field5882_"+row+"span").value;
		var val =  jQuery("#field5882_"+row).val();
		if(val!=""){
			array.push(val);
		}
		//array[i] = jQuery("#field5882_"+row+"span").text();
	}
	
	for(var j = 0; j < array.length-1; j++){
		for(var k = j+1; k < array.length; k++){
			if(jQuery.trim(array[j]) == jQuery.trim(array[k])){
				alert("类别重复,请重新输入!");
				return false;
			}
		}
	} 
	return true; 
}
</script>


